package com.suitsoft.ut.entity.thesis;


import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cascade;

import com.google.common.collect.Lists;
import com.suitsoft.ut.entity.IdEntity;
import com.suitsoft.ut.entity.account.User;
import com.suitsoft.ut.entity.base.College;
import com.suitsoft.ut.entity.base.Discipline;
import com.suitsoft.ut.entity.base.Student;
import com.suitsoft.ut.entity.commons.UploadFileInfo;
import com.suitsoft.ut.entity.commons.Weeklydiary;
import com.suitsoft.ut.util.upload.UploaderDBUtil;

/**
 * 题 信息实体
 *@author Suineg
 */
@Entity
@Table(name = "LW_THESIS")
public class Thesis extends IdEntity{
	/** 流程 */
	
	private ThesisFile thesisFile;
	
	/** 年度 */
	private String thesisYear;
	/** 院系 */
	
	private College college;
	/** 专业 */
	
	private Discipline discipline;
	/** 论文类别 1 - 理工类,2 - 文管类 */
	private Integer thesisType;
	/** 科题论文 */
	/** 论文地点 */
	private String thesisWorkWhere;
	/** 操作人 */
	
	private User opuser;
	/** 学号 */
	private String studentNo;
	/** 学生姓名 */
	private String studentName;
	/** 教师工号 */
	private String teacherNo;
	/** 教师名 */
	private String teacherName;
	/** 论文题目 */
	private String titile;
	/** 科题来源 */
	private Integer ketiSource;
	/** 职称 */
	private String teacherPost;
	/** 论文目的 */
	private String thesisDesignGoal;
	/** 论文简述 内容及要求 */
	private String thesisContent;
	/** 论文进度分配 */
	private String thesisProgress;
	/** 主要参考资料 */
	private String thesisReference;
	/** 指导答疑时间及地点 */
	private String thesisQaWhenWhere;
	/** 立题申报时间 */
	private Date setTheTime;
	/** 开题报告日期 */
	private Date openThesisDate;
	/** 设计论文开始时间 */
	private Date thesisStartDate;
	/** 设计论文结束日期 */
	private Date thesisEndDate;
	/** 论文背景说明 */
	private String thesisBackgroundNote;
	/** 主要内容 */
	private String openThesisContent;
	/** 工作方案及进度安排 */
	private String openThesisProgress;
	/** 参考资料 */
	private String openThesisReference;
	/** 学生自查表 */
	private String middleStudentSelf;
	/** 是否提交中期学生自查表 */
	private String isMiddleStudentSelf;
	/** 教师自查表 */
	private String middleTeacherSelf;
	/** 是否提交教师中期自查表 */
	private String isMiddleTeacherSelf;
	/** 是否被抽中期答辩 */
	private String isSpotMiddleReply;
	/** 上机时间 */
	private Long computerTime;
	/** 图纸个数 */
	private Long pectureCnt;
	/** 电路板 */
	private Long circuitboardCnt;
	/** 阅读文献个数 */
	private Long informationCnt;
	/** 读书笔记字数 */
	private Long readwriterCnt;
	/** 已选的学生 */
	private List<Student> students = Lists.newArrayList();
	/** 中期评分 */
	private Double middleScore;
	/** 答辩评分 */
	private Double dabianScore;
	/** 指导评分 */
	private Double zhidaoScore;
	/** 评阅教师评分 */
	private Double pingyueScore;
	/** 周记 */
	private List<Weeklydiary> weeklydiaries = Lists.newArrayList();
	/** 评分 */
	private List<ThesisScore> thesisScore = Lists.newArrayList();
	/** 上传文件 */
	private List<UploadFileInfo> uploadList = Lists.newArrayList();
	
	@OneToMany(fetch = FetchType.LAZY,mappedBy = "thesis")
	public List<UploadFileInfo> getUploadList() {
		return uploadList;
	}
	public void setUploadList(List<UploadFileInfo> uploadList) {
		this.uploadList = uploadList;
	}
	/**
	 * 中期的的上传文件
	 * @return
	 */
	@Transient
	public List<UploadFileInfo> getMiddleFile(){
		List<UploadFileInfo> list = null;
		if(this.uploadList != null){
			list = Lists.newArrayList();
			for(UploadFileInfo f : this.uploadList){
				if(Long.valueOf(UploaderDBUtil.MIDDLE).equals(f.getMiddleDabian())){
					list.add(f);
				}
			}
			
		}
		return list;
	}
	
	/**
	 * 答辩的上传文件
	 * @return
	 */
	@Transient
	public List<UploadFileInfo> getDaBianFile(){
		List<UploadFileInfo> list = null;
		if(this.uploadList != null){
			list = Lists.newArrayList();
			for(UploadFileInfo f : this.uploadList){
				if(Long.valueOf(UploaderDBUtil.DABIAN).equals(f.getMiddleDabian())){
					list.add(f);
				}
			}
			
		}
		return list;
	}
	/** 最终成绩 */
	private String endScore;
	@OneToMany(fetch = FetchType.LAZY,mappedBy = "thesis")
	@OrderBy("systemInfo")
	public List<ThesisScore> getThesisScore() {
		return thesisScore;
	}

	public void setThesisScore(List<ThesisScore> thesisScore) {
		this.thesisScore = thesisScore;
	}

	/**
	 * 根据周记类型  整理成Map形式
	 * <pre>Map<周记类型 , 周记实体></pre>
	 * @param type 周记类型
	 * @return
	 */
	@Transient
	public Map<Long,Weeklydiary> getWeeklydiaryMap(){
		Map<Long,Weeklydiary> map = new HashMap<Long,Weeklydiary>();
		for(Weeklydiary w : weeklydiaries){
			map.put(w.getDiaryType(), w);
		}
		return map;
	}

	@OneToMany(fetch = FetchType.LAZY,mappedBy="thesis")
	@OrderBy("diaryType")
	public List<Weeklydiary> getWeeklydiaries() {
		return weeklydiaries;
	}
	public void setWeeklydiaries(List<Weeklydiary> weeklydiaries) {
		this.weeklydiaries = weeklydiaries;
	}
	public String getThesisYear() {
		return thesisYear;
	}
	@OneToMany(fetch = FetchType.LAZY,mappedBy="thesis")
	@OrderBy("id")
	public List<Student> getStudents() {
		return students;
	}

	public void setStudents(List<Student> students) {
		this.students = students;
	}

	public void setThesisYear(String thesisYear) {
		this.thesisYear = thesisYear;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "COLLEGE_ID")
	public College getCollege() {
		return college;
	}
	public void setCollege(College college) {
		this.college = college;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "SPECIALITY_ID")
	public Discipline getDiscipline() {
		return discipline;
	}
	public void setDiscipline(Discipline discipline) {
		this.discipline = discipline;
	}
	public Integer getThesisType() {
		return thesisType;
	}
	public void setThesisType(Integer thesisType) {
		this.thesisType = thesisType;
	}
	public String getThesisWorkWhere() {
		return thesisWorkWhere;
	}
	public void setThesisWorkWhere(String thesisWorkWhere) {
		this.thesisWorkWhere = thesisWorkWhere;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "USER_ID")
	public User getOpuser() {
		return opuser;
	}
	public void setOpuser(User opuser) {
		this.opuser = opuser;
	}
	public String getStudentNo() {
		return studentNo;
	}
	public void setStudentNo(String studentNo) {
		this.studentNo = studentNo;
	}
	public String getStudentName() {
		return studentName;
	}
	public void setStudentName(String studentName) {
		this.studentName = studentName;
	}
	public String getTeacherNo() {
		return teacherNo;
	}
	public void setTeacherNo(String teacherNo) {
		this.teacherNo = teacherNo;
	}
	public String getTeacherName() {
		return teacherName;
	}
	public void setTeacherName(String teacherName) {
		this.teacherName = teacherName;
	}
	public String getTitile() {
		return titile;
	}
	public void setTitile(String titile) {
		this.titile = titile;
	}
	public String getTeacherPost() {
		return teacherPost;
	}
	public void setTeacherPost(String teacherPost) {
		this.teacherPost = teacherPost;
	}
	public String getThesisDesignGoal() {
		return thesisDesignGoal;
	}
	public void setThesisDesignGoal(String thesisDesignGoal) {
		this.thesisDesignGoal = thesisDesignGoal;
	}
	public String getThesisContent() {
		return thesisContent;
	}
	public void setThesisContent(String thesisContent) {
		this.thesisContent = thesisContent;
	}
	public String getThesisProgress() {
		return thesisProgress;
	}
	public void setThesisProgress(String thesisProgress) {
		this.thesisProgress = thesisProgress;
	}
	public String getThesisReference() {
		return thesisReference;
	}
	public void setThesisReference(String thesisReference) {
		this.thesisReference = thesisReference;
	}
	public String getThesisQaWhenWhere() {
		return thesisQaWhenWhere;
	}
	public void setThesisQaWhenWhere(String thesisQaWhenWhere) {
		this.thesisQaWhenWhere = thesisQaWhenWhere;
	}
	public Date getSetTheTime() {
		return setTheTime;
	}
	public void setSetTheTime(Date setTheTime) {
		this.setTheTime = setTheTime;
	}
	public Date getOpenThesisDate() {
		return openThesisDate;
	}
	public void setOpenThesisDate(Date openThesisDate) {
		this.openThesisDate = openThesisDate;
	}
	public Date getThesisStartDate() {
		return thesisStartDate;
	}
	public void setThesisStartDate(Date thesisStartDate) {
		this.thesisStartDate = thesisStartDate;
	}
	public Date getThesisEndDate() {
		return thesisEndDate;
	}
	public void setThesisEndDate(Date thesisEndDate) {
		this.thesisEndDate = thesisEndDate;
	}
	public String getThesisBackgroundNote() {
		return thesisBackgroundNote;
	}
	public void setThesisBackgroundNote(String thesisBackgroundNote) {
		this.thesisBackgroundNote = thesisBackgroundNote;
	}
	public String getOpenThesisContent() {
		return openThesisContent;
	}
	public void setOpenThesisContent(String openThesisContent) {
		this.openThesisContent = openThesisContent;
	}
	public String getOpenThesisProgress() {
		return openThesisProgress;
	}
	public void setOpenThesisProgress(String openThesisProgress) {
		this.openThesisProgress = openThesisProgress;
	}
	public String getOpenThesisReference() {
		return openThesisReference;
	}
	public void setOpenThesisReference(String openThesisReference) {
		this.openThesisReference = openThesisReference;
	}
	public String getMiddleStudentSelf() {
		return middleStudentSelf;
	}
	public void setMiddleStudentSelf(String middleStudentSelf) {
		this.middleStudentSelf = middleStudentSelf;
	}
	public String getIsMiddleStudentSelf() {
		return isMiddleStudentSelf;
	}
	public void setIsMiddleStudentSelf(String isMiddleStudentSelf) {
		this.isMiddleStudentSelf = isMiddleStudentSelf;
	}
	public String getMiddleTeacherSelf() {
		return middleTeacherSelf;
	}
	public void setMiddleTeacherSelf(String middleTeacherSelf) {
		this.middleTeacherSelf = middleTeacherSelf;
	}
	public String getIsMiddleTeacherSelf() {
		return isMiddleTeacherSelf;
	}
	public void setIsMiddleTeacherSelf(String isMiddleTeacherSelf) {
		this.isMiddleTeacherSelf = isMiddleTeacherSelf;
	}
	public String getIsSpotMiddleReply() {
		return isSpotMiddleReply;
	}
	public void setIsSpotMiddleReply(String isSpotMiddleReply) {
		this.isSpotMiddleReply = isSpotMiddleReply;
	}
	@OneToOne(fetch = FetchType.LAZY,mappedBy="thesis")
	@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
	public ThesisFile getThesisFile() {
		return thesisFile;
	}
	public void setThesisFile(ThesisFile thesisFile) {
		this.thesisFile = thesisFile;
	}
	public Integer getKetiSource() {
		return ketiSource;
	}
	public void setKetiSource(Integer ketiSource) {
		this.ketiSource = ketiSource;
	}
	public Long getComputerTime() {
		return computerTime;
	}
	public void setComputerTime(Long computerTime) {
		this.computerTime = computerTime;
	}
	public Long getPectureCnt() {
		return pectureCnt;
	}
	public void setPectureCnt(Long pectureCnt) {
		this.pectureCnt = pectureCnt;
	}
	public Long getCircuitboardCnt() {
		return circuitboardCnt;
	}
	public void setCircuitboardCnt(Long circuitboardCnt) {
		this.circuitboardCnt = circuitboardCnt;
	}
	public Long getInformationCnt() {
		return informationCnt;
	}
	public void setInformationCnt(Long informationCnt) {
		this.informationCnt = informationCnt;
	}
	public Long getReadwriterCnt() {
		return readwriterCnt;
	}
	public void setReadwriterCnt(Long readwriterCnt) {
		this.readwriterCnt = readwriterCnt;
	}
	public Double getMiddleScore() {
		return middleScore;
	}
	public void setMiddleScore(Double middleScore) {
		this.middleScore = middleScore;
	}
	public Double getDabianScore() {
		return dabianScore;
	}
	public void setDabianScore(Double dabianScore) {
		this.dabianScore = dabianScore;
	}

	public Double getZhidaoScore() {
		return zhidaoScore;
	}

	public void setZhidaoScore(Double zhidaoScore) {
		this.zhidaoScore = zhidaoScore;
	}

	public Double getPingyueScore() {
		return pingyueScore;
	}

	public void setPingyueScore(Double pingyueScore) {
		this.pingyueScore = pingyueScore;
	}

	public String getEndScore() {
		return endScore;
	}

	public void setEndScore(String endScore) {
		this.endScore = endScore;
	}
	@Transient
	public Double getAllScore(){
		return this.zhidaoScore + this.pingyueScore + this.dabianScore;
	}
}

